<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/common"/>
<%@ page import="net.sf.rose.business.service.DBMetaService" %>

	<form name="action_set_form" method="post" action="${path}/save.html" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">

		<div class="pageFormContent" layoutH="80">
		<div class="tabs">

				<div class="panelBar">
					<ul class="toolBar">
						<li><a class="add" onclick="add('添加操作');" title="添加操作"><span>导入</span></a><br /><br /></li>
						<li class="line">line</li>
						<li><a class="edit" onclick="moveActionUnit('up');" title="上移" ><span>上移</span></a></li>
						<li class="line">line</li>
						<li><a class="edit" onclick="moveActionUnit('down');" title="下移"><span>下移</span></a></li>
						<li class="line">line</li>
						<li><a class="delete" onclick="deleteActionUnit();"><span>删除</span></a></li>
					</ul>
				</div>
				
			<div class="tabsContent" style="height:98%;">
				<div>
					<table class="list nowrap itemDetail" addButton="添加参数" width="160%" >
						<thead>
							<tr>
								<th type="text" name="items.fieldName[#index#]" size="40" fieldClass="required">姓名</th>
								<th type="text" name="items.searchName[#index#]" size="20" fieldClass="required">国籍</th>
								<th type="text" name="items.replaceName[#index#]" size="20" fieldClass="required">职务</th>
								<th type="enum" name="items.type[#index#]" enumUrl="..${ctx}/common/view.html?jsp=define/dbmeta/data_type_list" size="23" fieldClass="required">性别</th>
								<th type="text" name="items.format[#index#]" size="10">生日</th>
								<th type="text" name="items.defaultValue[#index#]" size="10">出生地</th>
								<th type="enum" name="items.force[#index#]" enumUrl="..${ctx}/common/view.html?jsp=base/com/yes_no_list" size="2" >证件号码</th>
								<th type="text" name="items.defaultValue[#index#]" size="20">证件类型</th>
								<th type="text" name="items.defaultValue[#index#]" size="20">过期日期</th>
								<th type="text" name="items.defaultValue[#index#]" size="20">第二证件号码</th>
								<th type="text" name="items.defaultValue[#index#]" size="20">证件类型(第二)</th>
								<th type="text" name="items.defaultValue[#index#]" size="20">停留期</th>
								<th type="text" name="items.defaultValue[#index#]" size="20">出入事由</th>
								<th type="del" width="30">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:if test="${! empty bean.paramenters }">
							<c:forEach var="data" items="${bean.paramenters}" varStatus="status">
							<tr>
								<td><input type="text" class="required textInput" size="40" value="${data.fieldName}" name="items.fieldName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.searchName}" name="items.searchName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td>
									<select name="items.type[${status.index}]" class="combox">
										<%request.setAttribute("dataTypes", DBMetaService.getService().getAllDataType());%>
										<c:forEach var="type" items="${dataTypes}">
											<option value="${type}" <c:if test="${type==data.type}">selected</c:if> >${type}</option>
										</c:forEach>
									</select>
								</td>
								<td><input type="text" class="textInput" size="10" value="${data.format}" name="items.format[${status.index}]" /></td>
								<td><input type="text" class="textInput" size="10" value="${data.defaultValue}" name="items.defaultValue[${status.index}]" /></td>
								<td>
									<select name="items.force[${status.index}]" class="combox">
										<option value="1" <c:if test="${data.force}">selected</c:if> >是</option>
										<option value="0" <c:if test="${!data.force}">selected</c:if> >否</option>
									</select>
								</td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td><input type="text" class="required textInput" size="20" value="${data.replaceName}" name="items.replaceName[${status.index}]" /></td>
								<td><a class="btnDel " href="javascript:void(0)">删除</a></td>
							</tr>
							</c:forEach>
							</c:if>
						</tbody>
					</table>
				</div>
								
			</div>
			
			<div class="tabsFooter">
				<div class="tabsFooterContent"></div>
			</div>
		</div>

		</div>


	</form>

<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			// navTab.reload("${path}/list.html");//刷新
			$(bs_dock_list).submit();
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

function saveDock() {
	$("#bs_dock_edit").submit();
}

function deleteDock() {
	var rel = '';
	$('.bs_dock_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var url = "${path}/update.html?tableName=BS_DOCK&tableAction=delete&DOCK_ID=" + rel;
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/search.html?tableName=BS_DOCK&tableAction=list&jsp=ship/base/dock_list";
						navTab.reload(url);
						setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

function addBerth(){
	if("${dock.DOCK_ID}" == "") {
		alertMsg.warn('请先保存码头数据后再添加泊位信息！');
		return;
	}
	var url = "${path}/view.html?jsp=ship/base/dock_berth_edit&js_back_function=addBerthBack&DOCK_ID=${dock.DOCK_ID}";
	$.pdialog.open(url, "bs_dock_berth_add", "添加泊位操作",{width:800,height:480,mask:true,maxable:false,resizable:false});
}

function editBerth(){
	var rel = '';
	$('.bs_dock_berth_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条泊位数据！');
	}else{
		var url = "${path}/search.html?tableName=BS_BERTH&tableAction=load&jsp=ship/base/dock_berth_edit&js_back_function=addBerthBack&DOCK_ID=${dock.DOCK_ID}&BERTH_ID="+rel;
		$.pdialog.open(url, "bs_dock_berth_add", "编辑泊位操作",{width:800,height:480,mask:true,maxable:false,resizable:false});
	}
}

/**
 * 回调函数
 * 当泊位数据变更后，此方法重新从数据库中获取泊位信息
 */
function addBerthBack(){
	var params = $("#bs_dock_edit").serialize();
	params = decodeURIComponent(params,true);
	// 将值部分二次转码，以防出现中文乱码的问题
	params = convertUTF8(params);
	var url = "${path}/action.html?name=bs_dock_load&jsp=ship/base/dock_edit&"+ params;
	// 关闭子参照窗体
	$.pdialog.close("bs_dock_berth_add");
	// 重新打开本窗体
	$.pdialog.open(url, "ship_base_dock_edit", "修改码头信息",{width:800,height:480,mask:true,maxable:false,resizable:false});
}

/**
 * 将URL请求参数中值的部分二次转码，以防出现中文乱码
 * 例：actionType=&name=q&sort=q&description=q&dwz_rowNum=1&items.key%5B0%5D=q
 */
function convertUTF8(args){
	var params = "";
	var arr = args.split("&");
	for(var s in arr){
		var array = arr[s].split("=");
		if(array[1] != ""){
			params = params + '&' + array[0] + '=' + encodeURI(encodeURI(array[1]));
		}
	}
	return params.substr(1);
}

</script>